# ！ /usr/bin/python3
# -*- coding:utf-8 -*-
# @Author:Peng Cao
# @File: rq.py
# @Software: PyCharm
import requests
import json


class RunMain:
    @staticmethod
    def _send_get(url, data):
        res = requests.get(url=url, params=data).json()
        # return json.dumps(res, indent=2, sort_keys=True)
        return res

    @staticmethod
    def _send_post(url, data):
        res = requests.post(url=url, json=data).json()
        # return json.dumps(res, indent=2, sort_keys=True)
        return res

    def run_main(self, url, method, data=None):
        if method == "GET":
            res = self._send_get(url=url, data=data)
            return res
        if method == "POST":
            res = self._send_post(url=url, data=data)
            return res


if __name__ == '__main__':
    rm = RunMain()
    res = rm.run_main(url="http://www.baidu.com", method="GET")
    print(res.text)
